package com.med.service.impl;

import com.med.entity.CommentsDO;
import com.med.entity.DepartmentDO;
import com.med.entity.DoctorDO;
import com.med.entity.MedicalRecordDO;
import com.med.mapper.CommentsMapper;
import com.med.service.ICommentsService;
import com.med.utils.TreeMenuUtils;
import com.med.vo.CommentsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @BelongsProject: internet-based-healthcare
 * @BelongsPackage: com.med.service.impl
 * @Author: 小吴
 * @CreateTime: 2025-08-13 23:32
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class CommentsServiceImpl implements ICommentsService {
    @Autowired
    private CommentsMapper commentsMapper;


    /**
     * @Description: 查询所有部门
     * @Param:
     * @return:
     */
    @Override
    public List<DepartmentDO> queryDepartment() {
        List<DepartmentDO> queryDepartment = commentsMapper.queryDepartment();
        //构建树形菜单
        List<DepartmentDO> treeMenu = TreeMenuUtils.buildTreeMenu(queryDepartment);
        if (treeMenu != null) {
            return treeMenu;
        }
        return null;
    }

    /**
     * @Description: 根据部门id来查询医生
     * @Param:
     * @return:
     */
    @Override
    public List<DoctorDO> queryDoctorByCId(CommentsVO commentsVO) {
        List<DoctorDO> queryDoctorByDepartment = commentsMapper.queryDoctorByCId(commentsVO);
        if (queryDoctorByDepartment != null) {
            return queryDoctorByDepartment;
        }
        return null;
    }

    /**
    * @Description: 根据医生id进行查询其评论
    * @Param: 
    * @return:  
    */
    @Override
    public List<CommentsDO> queryDoctorComments(CommentsVO commentsVO) {
        List<CommentsDO> queryDoctorComments = commentsMapper.queryDoctorComments(commentsVO);
        if (queryDoctorComments != null) {
            return queryDoctorComments;
        }
        return null;
    }

    /**
     * @Description: 显示评论，条件查询不同医生的评论
     * @Param:
     * @return:
     */
    @Override
    public List<CommentsDO> queryComments(CommentsVO commentsVO) {
        List<CommentsDO> queryComments = commentsMapper.queryComments(commentsVO);
        if (queryComments != null) {
            return queryComments;
        }
        return null;
    }

    /**
    * @Description: 删除评论
    * @Param:
    * @return:
    */
    @Override
    public Integer updateComment(CommentsVO commentsVO) {
        Integer updateComment = commentsMapper.updateComment(commentsVO);
        if (updateComment != null) {
            return updateComment;
        }
        return null;
    }

    /**
    * @Description: 根据医生id和用户id查询详情
    * @Param:
    * @return:
    */
    @Override
    public MedicalRecordDO queryUserRecords(CommentsVO commentsVO) {
        MedicalRecordDO queryUserRecords = commentsMapper.queryUserRecords(commentsVO);
        if (queryUserRecords != null) {
            return queryUserRecords;
        }
        return null;
    }
}
